home *** CD-ROM | disk | FTP | other *** search
- Path: news.halcyon.com!usenet
- From: normanb@halcyon.com (Norm Bryar)
- Newsgroups: comp.lang.c++
- Subject: Re: C++ Questions.
- Date: Sat, 24 Feb 1996 18:52:22 GMT
- Organization: Northwest Nexus Inc.
- Message-ID: <4gnmo3$rvk@news.halcyon.com>
- References: <4gfocl$3do@thorn.cc.usm.edu>
- NNTP-Posting-Host: blv-pm11-ip3.halcyon.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- Flames? Probably not; most people on newsgroups are happy to answer
- questions. Be on the lookout for newsgroup items talking about the
- FAQ (frequently asked questions), however, and down load that.
-
- 1) A heap is a pool of memory. Windows 3.1 made a local heap (within
- the app's DS) and a global heap, the former faster but small, the
- latter larger but more overhead. Win32 gives each process one heap by
- default, but the process can allocate other heaps, usually because the
- programer wants to do custom memory management for faster or more
- diagnostic allocations. Win32 also allows you to create heaps that
- serialize access, i.e., two threads cannot bang against the heap
- simultaneously.
-
- 2) A virtual function cannot be resolved at compile time.
- This is connected with a topic called polymorphism: if you derive a
- bunch of classes from a base class, CBase, and you give this base
- class a set of virtual functions, then you can pass pointers or
- references (but not instances) of the derived classes about as if they
- were CBase references, but you still call the derived class functions.
-
- class CBase {
- virtual void print( void ) const
- { cout << "I'm a CBase\n"; }
- };
-
- class CDerived {
- virtual void print( void ) const
- { cout << "I'm a CDerived\n"; }
- };
-
- void Func1( CBase & anObj )
- {
- anObj.print();
- }
-
- CDerived myDer;
- CBase myBase;
-
- Func1( myDer );
- Fun1( myBase );
-
- output: "I'm a CDerived"
- "I'm a CBase"
-
- This is very, very useful and powerful and is at the heart of
- information hiding strategies that allow big projects to be developed
- without interdependencies, etc.
-
- 3) To tell the compiler how to do something differently.
- #ifdef _DEBUG tells the compiler to compile all code following until a
- #endif is encountered. You can thus optionaly define _DEBUG on the
- compiler command-line and generate a slow diagnostic build during
- development, then not define _DEBUG to generate smaller, faster code
- for release.
-
- #pragma pack(2) wlll tell the compiler to align structure or class
- member variables on two-byte boundaries for all structures following
- the pragma up until another #pragma pack() is encountered. Maybe the
- compiler was set to pack structures on 4- or 8-byte boundaries by
- default, but you need to maintain compatibility with another
- application's data for some of your structures.
-
- 4) Overloading means that you can specifiy a different behavior for
- something based on the context in which it appears.
-
- class X {
- void Show( ); // show to the screen be default
- void Show( HDC hDC ) // show to some other device, printer?
- void Show( HMETAFILE hM ) // show yet somewhere else
- }
-
- Overloading operators is convenient. A string might overload
- operator+(CString toAppend) to append another stirng to itself.
-
- 5) Run-time means when the program runs, instead of when it compiles.
- In 2) above, Func1( CBase & anObj ) could only resolve which print()
- method to call at runtime.
-
- 6) Um, there are as many as you define, certainly.
- By types of classes you mean like templates (aka parameterized
- classes), single-inheritence, multiple-inheritnece,
- multiple-virtual-inheritence, etc.?
-
- Hope this helps.
- --Norm
-
-
- afalgout@ocean.st.usm.edu (Andrew Wilson Falgout) wrote:
-
- >Ok here it goes. I know I'll probably receive a few flames from showing
- >my lack of knowledge but I need answers.
- >1> What is the Heap exactly? Is it similar to a stack? Or is it just
- > another word for a pool of memory.
- >2> What is the difference between a virtual function and a normal function.
- >3> What is the purpose of precompiler directives? An example would
- > probably help me understand this one better.
- >4> Is there an easy way to explain Overloading things? Like Overloading
- > an Operator.
- >5> What is run-time?
- >6> How many different type/kinds of classes are there. And what's the
- > difference between them?
- > There are many more questions that come to mind but I really don't
- >wish to take up anymore of everyone's time right now. Thank you for
- >whatever help I get. And please don't flame a person who wants to learn.
-
- >Thanks,
- >Andrew Falgout
-
- >-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+--+-+-+-+-+-+-
- > "And remember, No matter where you go. There you are."
- > Andrew Wilson Falgout
- > AKA: Kodos, Terok, Sabrina, and Gallus
- >-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
-
-
-